package com.kaiyidiannao.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.kaiyidiannao.main.R;

import java.util.ArrayList;

/**
 * Created by mark on 2014/4/15.
 */
public class ImageAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Bitmap> arrayList;

    public ImageAdapter(Context context, ArrayList<Bitmap> bmpList) {
        this.context = context;
        this.arrayList = bmpList;
    }

    @Override
    public int getCount() {
        return arrayList == null ? 0 : arrayList.size();
    }

    //设置设配器数据
    public void setDate(ArrayList<Bitmap>bmpList){
        this.arrayList=bmpList;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView=View.inflate(context, R.layout.grid_item, null);
            viewHolder=new ViewHolder();
            viewHolder.imageView=(ImageView) convertView.findViewById(R.id.uploadImageView);
            convertView.setTag(viewHolder);
        }
        else {
            viewHolder=(ViewHolder) convertView.getTag();
        }
        viewHolder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        viewHolder.imageView.setLayoutParams(new LinearLayout.LayoutParams(100, 120));
        //设置设配器数据
        int [] parameter={arrayList.get(position).getWidth(),arrayList.get(position).getHeight()};
        viewHolder.imageView.setTag(parameter);
        viewHolder.imageView.setImageBitmap(arrayList.get(position));
        return convertView;
    }
    class ViewHolder{
        ImageView imageView;
    }
}
